package com.czk.doc;

import com.czk.util.ClientUtil;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

/**
 * 批量删除
 *
 * @Author:ChenZhangKun
 * @Date: 2021/6/13 23:39
 */
public class BenchDelete {
    public static void main(String[] args) throws IOException {
        // 客户端
        RestHighLevelClient highLevelClient = ClientUtil.getHighLevelClient();
        BulkRequest bulkRequest = new BulkRequest();
        // 批量删除
        bulkRequest.add(new DeleteRequest().index("user").id("1"));
        bulkRequest.add(new DeleteRequest().index("user").id("3"));
        bulkRequest.add(new DeleteRequest().index("user").id("5"));
        BulkResponse bulk = highLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
        System.out.println(bulk.getTook());
        System.out.println(bulk.getItems());
        highLevelClient.close();
    }
}
